# Maintainer:  Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Contributor: carstene1ns <url/mail: arch carsten-teibes de>
# Contributor: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>


_realname=SDL2_sound
pkgbase=mingw-w64-${_realname}-hg
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-hg
pkgver=r596.719dade41745
pkgrel=1
pkgdesc="A library to decode several popular sound file formats, patched for SDL2 (dev version)"
arch=('any')
url="https://icculus.org/${_realname}/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-libmodplug"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-speex"
         "${MINGW_PACKAGE_PREFIX}-physfs-hg")
makedepends=('mercurial')
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('strip' 'staticlibs')
source=(${_realname}::"hg+https://hg.icculus.org/icculus/SDL_sound"
        'pkgconfig.patch'
        'physfs-renamed-export.patch'
        'no-undefined.patch'
        'rename-like-SDL2.patch')
sha256sums=('SKIP'
            '5f2a417f408d6b4afdc9ac57f1bdbd7f2262efa9de80ff8d2da3325fcb980d14'
            'd7bd96390d9bc877c0204922c7c4666cadfdccc5e6c0cfcf9477d113377f5d10'
            '87a2872d6248be64086c3eb7d4b03e6a36d69243971844abe136a3d41e3b91bc'
            '0646bfb4ef53aaa5c446eea6c826e5b9c16a27af3edbc85dc6493d49c1e865a9')

pkgver() {
  cd ${_realname}
  printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
}

prepare() {
  cd ${srcdir}/${_realname}
  # fix deprecated physfs declaration
  patch -Np1 -i ${srcdir}/physfs-renamed-export.patch
  # patch for SDL2 and pkgconfig support
  patch -Np1 -i ${srcdir}/pkgconfig.patch
  patch -Np1 -i ${srcdir}/no-undefined.patch
  patch -Np1 -i ${srcdir}/rename-like-SDL2.patch
  ./bootstrap
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-mikmod

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}/" install
}
